<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>댓글 시스템</title>
</head>
<body>
 ${ sessionScope.user.name } ( ${ sessionScope.user.description } )
	
	<table>
		<tr>
			<form action="modify" method="POST" commandName="id">
				<input type="submit" value="프로필수정">
				<input type="hidden" name="id" value="${sessionScope.user.name}">
			</form>
			<input type="submit" value="글쓰기"
				onclick="window.open('write','small','width=750, height=500, scrollbars=yes, menubar=no')">
		</tr>
		<c:forEach items="${commentList}" var="comment">
			<tr>
				<td><img name="writer_img" alt="" src="people.png" /></td>
				<td>${comment.name}</td>
				<td>${comment.comment}</td>
				<td>
					<form action="logincomment/recommend" method="GET" commandName="seq_num">
						<input type="submit" value="추천(${comment.recommend})">
						<input type="hidden" name="seq_num" value="${comment.seq_num}">
					</form>
				</td>
				<td>
					<form action="logincomment/oppose" method="GET" commandName="seq_num">
						<input type="submit" value="반대(${comment.oppose})">
						<input type="hidden" name="seq_num" value="${comment.seq_num}">
					</form>
				</td>
					<script type="text/javascript">
						buttonHideOrVisible('${sessionScope.user.name}', '${comment.name}');
					</script>
				<td>
					<form action="logincomment/delete" method="GET" commandName="seq_num">
						<input type="submit" name="deleteBtn" value="삭제">
						<input type="hidden" name="seq_num" value="${comment.seq_num}">
					</form>
				</td>
				<td>${comment.date}</td>
			</tr>
		</c:forEach>
	</table>
</body>
</html>

<script type="text/javascript">
function buttonHideOrVisible(user, commentUser){
	if(user.value == commentUser.value){
		document.getElementById('deleteBtn').style.visibility = 'visible';  
    }else{
     	document.getElementById('deleteBtn').style.visibility = 'hidden';
	}
}
</script>